/**
  ******************************************************************************
  * @file    w32f006_crs.h
  * @author  WeiLink Technology 
  * @version V1.0.0
  * @date    09/01/2020
  * @brief   This file contains all the functions prototypes for the CRS 
  *          firmware library.
  ******************************************************************************
  * @attention
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, WeiLink Technology SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * <h2><center>&copy; COPYRIGHT WeiLink Technology</center></h2>
  ******************************************************************************  
  */ 

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __W32F006_CRS_H
#define __W32F006_CRS_H

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "w32f006.h"

/** @addtogroup W32F006_StdPeriph_Driver
  * @{
  */

/** @addtogroup CRS
  * @{
  */ 

/* Exported types ------------------------------------------------------------*/

/** 
  * @brief  CRS Init Structure definition  
  */ 
typedef struct
{
	uint32_t CRS_Reload;

	uint32_t CRS_FELim;
	
	uint32_t CRS_SyncDiv;          
	
	uint32_t CRS_SyncSrc;           
	
	uint32_t CRS_SyncPol;              
	
	uint32_t CRS_AutoTrimEN;              
} CRS_InitTypeDef;

/* Exported constants --------------------------------------------------------*/

/** @defgroup CRS_Exported_Constants
  * @{
  */ 

/** @defgroup CRS_Reload 
  * @{
  */ 
#define IS_CRS_Reload(VAL)                  ((VAL) < 0x10000)
/**
  * @}
  */ 

/** @defgroup CRS_FELim 
  * @{
  */ 
#define IS_CRS_FELim(VAL)                   ((VAL) < 0x100)
/**
  * @}
  */ 

/** @defgroup CRS_SyncDiv 
  * @{
  */ 
#define CRS_SYNC_DIV_1                      CRS_CFGR_SYNCDIV_1
#define CRS_SYNC_DIV_2                      CRS_CFGR_SYNCDIV_2
#define CRS_SYNC_DIV_4                      CRS_CFGR_SYNCDIV_4
#define CRS_SYNC_DIV_8                      CRS_CFGR_SYNCDIV_8
#define CRS_SYNC_DIV_16                     CRS_CFGR_SYNCDIV_16
#define CRS_SYNC_DIV_32                     CRS_CFGR_SYNCDIV_32
#define CRS_SYNC_DIV_64                     CRS_CFGR_SYNCDIV_64
#define CRS_SYNC_DIV_128                    CRS_CFGR_SYNCDIV_128
#define IS_CRS_SYNC_DIV(DIV) 	           (((DIV) == CRS_CFGR_SYNCDIV_1)  || \
                                      		((DIV) == CRS_CFGR_SYNCDIV_2)  || \
											((DIV) == CRS_CFGR_SYNCDIV_4)  || \
											((DIV) == CRS_CFGR_SYNCDIV_8)  || \
											((DIV) == CRS_CFGR_SYNCDIV_16) || \
											((DIV) == CRS_CFGR_SYNCDIV_32) || \
											((DIV) == CRS_CFGR_SYNCDIV_64) || \
											((DIV) == CRS_CFGR_SYNCDIV_128))
/**
  * @}
  */ 

/** @defgroup CRS_SyncSrc 
  * @{
  */ 
#define CRS_SYNC_SRC_GPIO                   CRS_CFGR_SYNCSRC_GPIO
#define CRS_SYNC_SRC_SOF                    CRS_CFGR_SYNCSRC_SOF
#define IS_CRS_SYNC_SRC(SRC) 	           (((SRC) == CRS_SYNC_SRC_GPIO)  || \
											((SRC) == CRS_SYNC_SRC_SOF))
/**
  * @}
  */ 

/** @defgroup CRS_SyncPol 
  * @{
  */ 
#define CRS_Sync_POL_RISE                   ((uint32_t)0x00000000)
#define CRS_Sync_POL_FALL                   ((uint32_t)0x80000000)
#define IS_CRS_Sync_POL(POL)               (((POL) == CRS_Sync_POL_RISE)   || \
                                            ((POL) == CRS_Sync_POL_FALL))
/**
  * @}
  */ 

/** @defgroup CRS_AutoTrimEN 
  * @{
  */ 
#define CRS_AUTO_TRIM_ENABLE                ((uint32_t)0x00000040)
#define CRS_AUTO_TRIM_DISABLE               ((uint32_t)0x00000000)
 
#define IS_CRS_AUTO_TRIM(TRIM)             (((TRIM) == CRS_AUTO_TRIM_ENABLE)    || \
                                            ((TRIM) == CRS_AUTO_TRIM_DISABLE))
/**
  * @}
  */ 

/** @defgroup CRS_Interrupt_definition 
  * @{
  */
#define CRS_IT_SYNCOK                       ((uint32_t)0x00000001)
#define CRS_IT_SYNCWARN                     ((uint32_t)0x00000002)
#define CRS_IT_ERR                          ((uint32_t)0x00000004)
#define CRS_IT_ESYNC                        ((uint32_t)0x00000008)

#define IS_CRS_CONFIG_IT(IT)               (((IT) != 0) && (((IT) & ((uint32_t)0xFFFFFFF0)) == 0))
#define IS_CRS_GET_IT(IT)                  (((IT) == CRS_IT_SYNCOK) || ((IT) == CRS_IT_SYNCWARN) || \
                                            ((IT) == CRS_IT_ERR)   || ((IT) == CRS_IT_ESYNC))
#define IS_CRS_CLEAR_IT(IT) 			   (((IT) != 0) && (((IT) & ((uint32_t)0xFFFFFFF0)) == 0))
/**
  * @}
  */

/** @defgroup CRS_Flags 
  * @{
  */
#define CRS_FLAG_FEDIR                     ((uint32_t)0x00008000)
#define CRS_FLAG_TRIMOVF                   ((uint32_t)0x00000400)
#define CRS_FLAG_SYNCMISS                  ((uint32_t)0x00000200)
#define CRS_FLAG_SYNCERR                   ((uint32_t)0x00000100)
#define IS_CRS_FLAG(FLAG)                 (((FLAG) == CRS_FLAG_FEDIR) || ((FLAG) == CRS_FLAG_TRIMOVF) || \
                                           ((FLAG) == CRS_FLAG_SYNCMISS) || ((FLAG) == CRS_FLAG_SYNCERR))
/**
  * @}
  */ 

/**
  * @}
  */ 

/* Exported macro ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
void CRS_DeInit(void);
void CRS_Init(CRS_InitTypeDef* CRS_InitStruct);
void CRS_StructInit(CRS_InitTypeDef* CRS_InitStruct);
void CRS_SoftSync(void);
void CRS_Cmd(FunctionalState NewState);
FlagStatus CRS_GetFlagStatus(uint32_t CRS_FLAG);
void CRS_ITConfig(uint32_t CRS_IT, FunctionalState NewState);
ITStatus CRS_GetITStatus(uint32_t CRS_IT);
void CRS_ClearITPendingBit(uint32_t CRS_IT);

#ifdef __cplusplus
}
#endif

#endif /* __W32F006_CRS_H */

/**
  * @}
  */ 

/**
  * @}
  */ 

/******************* (C) COPYRIGHT WeiLink Technology *****END OF FILE****/
